#define DEBUG
#include <cstdio>
#include <cmath>
#define MAXN 1000000000

using namespace std;

#define MAXP 1000
void getPrime(int *p, int n) {
  static bool book[MAXP+1];

  p[0] = 0;
  book[1] = true;
  for (int i=2; i<=n; i++) {
    if (!book[i]) {
      p[++p[0]] = i;
      for (int j=2; i*j<=n; j++) {
	book[i*j]=true;
      }
    }
  }
}

int check(int *prime, int n, int s, int flag, int limit) {
  int ret=0;
  for (int i=limit; i<=prime[0]; i++) {
    if (s*prime[i]<=n) {
      ret += n/(s*prime[i])*flag+check(prime, n, s*prime[i], -flag, i+1);
    }
  }
  return ret;
}

int solve1(int p, int n) {
  if (n==1) {
    return p;
  }

  static int prime[MAXP+1];
  getPrime(prime, p-1);

  int ans=0;
  for (int l=p, r=MAXN/p, mid; l<=r; ) {
    mid=(l+r)/2;
    if (mid-check(prime, mid, 1, 1, 1)<n) {
      l = mid+1;
    } else {
      ans = mid;
      r = mid-1;
    }
  }
  return ans*p;
}

int getFirstPrime(int x) {
  int t=sqrt(x);
  for (int i=2; i<=t; i++) {
    if (x%i==0) {
      return i;
    }
  }
  return x;
}

int solve2(int p, int n) {
  if (MAXN/p-p<n) {
    return 0;
  }
  if (n==1) {
    return p;
  }
  n--;
  for (int i=p; i<=MAXN/p; i++) {
    if (getFirstPrime(i)>=p) {
      n--;
    }
    if (!n) {
      return p*i;
    }
  }
  return 0;
}

int main() {
#ifdef DEBUG
  freopen("3188.in", "r", stdin);
  freopen("3188.out", "w", stdout);
#endif

  int n, p;
  scanf("%d %d", &n, &p);

  printf("%d", p<1000 ? solve1(p, n) : solve2(p, n));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
